package com.gisocn.onemap.utils;

import android.content.Context;
import com.gisocn.onemap.base.Constant;
import java.io.File;

/* loaded from: classes2.dex */
public class FileUtils {
    String FileName = Constant.SAVE_PATH + "shp/";
    String filePathName2 = "/storage/emulated/0/Android/data/com.gisocn.onemap/files/offline_download/shape/ghdk_kg2.shp";

    public static File getLocalFile(String str, Context context) {
        return new File(Constant.SAVE_PATH + "/tpk", str);
    }

    public static boolean isLocalExistPath(String str, Context context) {
        return new File(str).exists();
    }

    public static boolean isLocalExist(String str, Context context) {
        return getLocalFile(str, context).exists();
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x0050 A[Catch: Exception -> 0x0092, LOOP:0: B:27:0x0050->B:72:0x0050, LOOP_START, TryCatch #0 {Exception -> 0x0092, blocks: (B:3:0x0005, B:6:0x001b, B:9:0x0023, B:25:0x004b, B:27:0x0050, B:40:0x006c, B:48:0x007d, B:51:0x0085, B:55:0x008e, B:13:0x002b, B:15:0x002f, B:18:0x0036, B:20:0x003c, B:22:0x0042), top: B:60:0x0005 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static java.lang.String getCharset(java.io.File r8) {
        /*
            java.lang.String r0 = "GBK"
            r1 = 3
            byte[] r2 = new byte[r1]
            java.io.BufferedInputStream r3 = new java.io.BufferedInputStream     // Catch: java.lang.Exception -> L92
            java.io.FileInputStream r4 = new java.io.FileInputStream     // Catch: java.lang.Exception -> L92
            r4.<init>(r8)     // Catch: java.lang.Exception -> L92
            r3.<init>(r4)     // Catch: java.lang.Exception -> L92
            r8 = 0
            r3.mark(r8)     // Catch: java.lang.Exception -> L92
            int r1 = r3.read(r2, r8, r1)     // Catch: java.lang.Exception -> L92
            r4 = -1
            if (r1 != r4) goto L1b
            return r0
        L1b:
            r1 = r2[r8]     // Catch: java.lang.Exception -> L92
            java.lang.String r5 = "UTF-8"
            r6 = -2
            r7 = 1
            if (r1 != r4) goto L2b
            r1 = r2[r7]     // Catch: java.lang.Exception -> L92
            if (r1 != r6) goto L2b
            java.lang.String r0 = "UTF-16LE"
        L29:
            r8 = 1
            goto L4b
        L2b:
            r1 = r2[r8]     // Catch: java.lang.Exception -> L92
            if (r1 != r6) goto L36
            r1 = r2[r7]     // Catch: java.lang.Exception -> L92
            if (r1 != r4) goto L36
            java.lang.String r0 = "UTF-16BE"
            goto L29
        L36:
            r1 = r2[r8]     // Catch: java.lang.Exception -> L92
            r6 = -17
            if (r1 != r6) goto L4b
            r1 = r2[r7]     // Catch: java.lang.Exception -> L92
            r6 = -69
            if (r1 != r6) goto L4b
            r1 = 2
            r1 = r2[r1]     // Catch: java.lang.Exception -> L92
            r2 = -65
            if (r1 != r2) goto L4b
            r0 = r5
            goto L29
        L4b:
            r3.reset()     // Catch: java.lang.Exception -> L92
            if (r8 != 0) goto L8e
        L50:
            int r8 = r3.read()     // Catch: java.lang.Exception -> L92
            if (r8 == r4) goto L8e
            r1 = 240(0xf0, float:3.36E-43)
            if (r8 < r1) goto L5b
            goto L8e
        L5b:
            r1 = 191(0xbf, float:2.68E-43)
            r2 = 128(0x80, float:1.8E-43)
            if (r2 > r8) goto L64
            if (r8 > r1) goto L64
            goto L8e
        L64:
            r6 = 192(0xc0, float:2.69E-43)
            if (r6 > r8) goto L75
            r6 = 223(0xdf, float:3.12E-43)
            if (r8 > r6) goto L75
            int r8 = r3.read()     // Catch: java.lang.Exception -> L92
            if (r2 > r8) goto L8e
            if (r8 > r1) goto L8e
            goto L50
        L75:
            r6 = 224(0xe0, float:3.14E-43)
            if (r6 > r8) goto L50
            r6 = 239(0xef, float:3.35E-43)
            if (r8 > r6) goto L50
            int r8 = r3.read()     // Catch: java.lang.Exception -> L92
            if (r2 > r8) goto L8e
            if (r8 > r1) goto L8e
            int r8 = r3.read()     // Catch: java.lang.Exception -> L92
            if (r2 > r8) goto L8e
            if (r8 > r1) goto L8e
            r0 = r5
        L8e:
            r3.close()     // Catch: java.lang.Exception -> L92
            goto L96
        L92:
            r8 = move-exception
            r8.printStackTrace()
        L96:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.gisocn.onemap.utils.FileUtils.getCharset(java.io.File):java.lang.String");
    }

    public void deFile(String str) {
        File file = new File(str);
        File file2 = new File(this.filePathName2);
        File file3 = new File(str);
        file.delete();
        file2.renameTo(file3);
    }

    public static boolean deleteFile(String str) {
        File[] listFiles;
        File file = new File(str);
        if (file.exists()) {
            boolean z = true;
            for (File file2 : file.listFiles()) {
                if (file2.isFile()) {
                    z = file.delete();
                } else if (file2.isDirectory()) {
                    z = deleteFile(file2.getAbsolutePath());
                }
            }
            return z;
        }
        return false;
    }

    public static void deleteDir(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                File[] listFiles = file.listFiles();
                if (listFiles == null || listFiles.length == 0) {
                    return;
                }
                for (int i = 0; i < listFiles.length; i++) {
                    if (!listFiles[i].getName().contains("zip")) {
                        deleteDir(listFiles[i]);
                    }
                }
                return;
            }
            L.e("删除整个文件夹fileUtils" + file.getAbsolutePath());
            file.delete();
        }
    }
}
